package com.bp.system.service.impl;

import com.bp.system.domain.SysNoticeReadStatus;
import com.bp.system.mapper.SysNoticeReadStatusMapper;
import com.bp.system.service.ISysNoticeReadStatusService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author shaominjie
 * @Description TODO
 * @date %{DATE} 16:36
 */
@Service
public class SysNoticeReadStatusServiceImpl implements ISysNoticeReadStatusService {

    private Logger logger = LoggerFactory.getLogger(SysNoticeReadStatusServiceImpl.class);

    @Resource
    private SysNoticeReadStatusMapper noticeReadStatusMapper;

    @Override
    public int insert(SysNoticeReadStatus readStatus) {
        return noticeReadStatusMapper.insert(readStatus);
    }

    @Override
    public int insertAll(List<SysNoticeReadStatus> list, String loginName) {
        if(CollectionUtils.isEmpty(list)) {
            return 0;
        }
        Date now =  new Date();
        return noticeReadStatusMapper.insertAll(list.stream().map(e ->{e.setCreateBy(loginName);e.setCreateTime(now); return e; }).collect(Collectors.toList()));
    }

    @Override
    public int update(Long id, String status, String loginName) {
        return noticeReadStatusMapper.update(id,status,loginName,new Date());
    }

    @Override
    public int updateByUserId(Long userId, String status, String loginName) {
        return noticeReadStatusMapper.updateByUserId(userId,status,loginName,new Date());
    }

    @Override
    public int updateByNoticeIdAndUserId(Long noticeId, Long userId, String status, String loginName) {
        return noticeReadStatusMapper.updateByNoticeIdAndUserId(noticeId,userId,status,loginName,new Date());
    }

    @Override
    public int updateAll(Long[] ids, String status, String loginName) {
        return noticeReadStatusMapper.updateAll(ids,status);
    }

    @Override
    public int deleteByNoticeId(Long noticeId, String loginName) {
        return noticeReadStatusMapper.deleteByNoticeId(noticeId);
    }

    @Override
    public int deleteByUserId(Long userId, String loginName) {
        return noticeReadStatusMapper.deleteByUserId(userId);
    }

    @Override
    public int deleteByUserIds(Long[] userIds, String loginName) {
        return noticeReadStatusMapper.deleteByUserIds(userIds);
    }

    @Override
    public int deleteByDeptId(Long deptId, String loginName) {
        return noticeReadStatusMapper.deleteByDeptId(deptId);
    }

    @Override
    public int deleteByDeptIds(Long[] deptIds, String loginName) {
        return noticeReadStatusMapper.deleteByDeptIds(deptIds);
    }

    @Override
    public int delete(Long id, String loginName) {
        return noticeReadStatusMapper.delete(id);
    }

    @Override
    public List<SysNoticeReadStatus> selectByUserId(Long userId, String status) {
        return noticeReadStatusMapper.selectByUserId(userId,status);
    }

    @Override
    public List<SysNoticeReadStatus> selectByNoticeId(Long noticeId, String status) {
        return noticeReadStatusMapper.selectByNoticeId(noticeId,status);
    }

    @Override
    public int deleteByNoticeIds(Long[] toLongArray) {
        return noticeReadStatusMapper.deleteByNoticeIds(toLongArray);
    }
}
